package xyz.pro5books.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.pro5books.pojo.Msg;
import xyz.pro5books.service.MsgService;
import xyz.pro5books.vo.MsgVO;
import xyz.pro5books.vo.SysResult;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/msg")
public class MsgController {
    @Autowired
    private MsgService msgService;
    //插入消息
    @PostMapping("/sendMsg")
    public SysResult sendMsg(@RequestBody Msg msg){
        msgService.saveMsg(msg);
        return SysResult.success();
    }

    @GetMapping("/getMsgList/{userId}")
    public SysResult getMsgList(@PathVariable Integer userId){
        List<MsgVO> msgVOList = msgService.getMsgList(userId);
        return SysResult.success(msgVOList);
    }

    @DeleteMapping("/deleteMsg/{msgId}")
    public SysResult deleteMsg(@PathVariable Integer msgId){
        msgService.deleteMsg(msgId);
        return SysResult.success();
    }

    @PutMapping("/changeToReaded/{msgId}")
    public SysResult changeToReaded(@PathVariable Integer msgId){
        msgService.changeToReaded(msgId);
        return SysResult.success();
    }

    @GetMapping("/getMessageNum/{userId}")
    public SysResult getMessageNum(@PathVariable Integer userId){
        return SysResult.success(msgService.getMessageNum(userId));
    }
}
